// Copyright 2011 Edward Wahlen. All Rights Reserved.

package org.wahlen.pc;

import org.wahlen.io.Marshallers;
import org.wahlen.util.Pair;

/**
 * @author edward.wahlen@gmail (Edward Wahlen)
 */
public class PType<T> {

  private static final PType<Integer> VARINT = from(Marshallers.unboxedVarInt());
  private static final PType<Void> VOID = from(Marshallers.VOID_MARSHALLER);

  public final Marshaller<T> marshaller;

  private PType(Marshaller<T> marshaller) {
    this.marshaller = marshaller;
  }

  public static <F, S> PType<Pair<F, S>> pair(PType<F> f, PType<S> s) {
    return from(Marshallers.getPair(f.marshaller, s.marshaller));
  }

  public static <T> PType<T> from(Marshaller<T> marshaller) {
    return new PType<T>(marshaller);
  }

  public static PType<Integer> varint() {
    return VARINT;
  }

  public static PType<Void> voidType() {
    return VOID;
  }
}
